/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.ArrayList;
import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.FlightInfo;
import com.sasis.dao.FlightInfoDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class FlightInfoDaoiBatis extends BaseDaoiBATIS implements FlightInfoDao {

    /**
     * @see com.sasis.dao.FlightInfoDao#getFlightInfos(com.sasis.model.FlightInfo)
     */
    public List getFlightInfos(final FlightInfo flightInfo) {
    	List list=new ArrayList();           
        list=getSqlMapClientTemplate().queryForList("getFlightInfos", flightInfo);
        return list;
    }

    /**
     * @see com.sasis.dao.FlightInfoDao#getFlightInfo(Integer id)
     */
    public FlightInfo getFlightInfo(Integer id) {
    	FlightInfo flightInfoVal=new FlightInfo();
    	flightInfoVal.setId(id);
        FlightInfo flightInfo = (FlightInfo) getSqlMapClientTemplate().queryForObject("getFlightInfo", flightInfoVal);

        if (flightInfo == null) {
        	flightInfo=new FlightInfo();
            //throw new ObjectRetrievalFailureException(FlightInfo.class, flightInfoVal);
       }

        return flightInfo;
    }
    
    public FlightInfo getFlightInfo(final FlightInfo flightInfoVal){
    	FlightInfo flightInfo = new FlightInfo();
    	List flightInfolist = (List) getSqlMapClientTemplate().queryForList("getFlightInfo", flightInfoVal);
    	if(null!=flightInfolist&&flightInfolist.size()>0){
    		flightInfo=(FlightInfo)flightInfolist.get(0);
    	}else{
    		flightInfo=null;
    	}
    	return flightInfo;
    }

    /**
     * @see com.sasis.dao.FlightInfoDao#saveFlightInfo(FlightInfo flightInfo)
     */    
    public void saveFlightInfo(final FlightInfo flightInfo) {
        Integer id = flightInfo.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addFlightInfo", flightInfo);
        } else {
            getSqlMapClientTemplate().update("updateFlightInfo", flightInfo);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(FlightInfo.class, id);
        }
    }

    /**
     * @see com.sasis.dao.FlightInfoDao#removeFlightInfo(Integer id)
     */
    public void removeFlightInfo(FlightInfo flightInfo) {
        getSqlMapClientTemplate().update("deleteFlightInfo",  flightInfo);
    }
}
